home *** CD-ROM | disk | FTP | other *** search
- package symantec.itools.db.net;
-
- import java.io.DataOutputStream;
- import java.io.IOException;
- import symjava.lang.Bignum;
- import symjava.sql.SQLException;
-
- class SmallInt extends NumberField {
- short _iVal;
-
- int getType() {
- return 85;
- }
-
- void readData(ServerObject data) throws SQLException, IOException, ErrorException {
- this._iVal = ((NetData)data).getShort();
- }
-
- void writeData(DataOutputStream os) throws IOException {
- NetData data = new NetData(this._iVal);
- data.write(os);
- }
-
- public String getString() throws SQLException {
- return ((Field)this).isNull() ? null : String.valueOf(this._iVal);
- }
-
- public boolean getBoolean() throws SQLException {
- if (((Field)this).isNull()) {
- return false;
- } else {
- return this._iVal != 0;
- }
- }
-
- public byte getByte() throws SQLException {
- return ((Field)this).isNull() ? 0 : (byte)this._iVal;
- }
-
- public short getShort() throws SQLException {
- return ((Field)this).isNull() ? 0 : this._iVal;
- }
-
- public int getInt() throws SQLException {
- return ((Field)this).isNull() ? 0 : this._iVal;
- }
-
- public long getLong() throws SQLException {
- return ((Field)this).isNull() ? 0L : (long)this._iVal;
- }
-
- public float getFloat() throws SQLException {
- return ((Field)this).isNull() ? 0.0F : (float)this._iVal;
- }
-
- public double getDouble() throws SQLException {
- return ((Field)this).isNull() ? (double)0.0F : (double)this._iVal;
- }
-
- public Bignum getBignum(int scale) throws SQLException {
- return ((Field)this).isNull() ? null : new Bignum(this._iVal, scale);
- }
-
- public void setBoolean(boolean x) throws SQLException {
- if (x) {
- this._iVal = 1;
- } else {
- this._iVal = 0;
- }
-
- super._null = false;
- }
-
- public void setByte(byte x) throws SQLException {
- this._iVal = (short)x;
- super._null = false;
- }
-
- public void setShort(short x) throws SQLException {
- this._iVal = x;
- super._null = false;
- }
-
- public void setInt(int x) throws SQLException {
- this.validateRange(x);
- this._iVal = (short)x;
- super._null = false;
- }
-
- public void setLong(long x) throws SQLException {
- this._iVal = (short)((int)x);
- super._null = false;
- }
-
- public void setFloat(float x) throws SQLException {
- Float f = new Float(x);
- int i = f.intValue();
- this.validateRange(i);
- this._iVal = (short)i;
- super._null = false;
- }
-
- public void setDouble(double x) throws SQLException {
- Double d = new Double(x);
- int i = d.intValue();
- this.validateRange(i);
- this._iVal = (short)i;
- super._null = false;
- }
-
- public void setBignum(Bignum x) throws SQLException {
- int i = x.intValue();
- this.validateRange(i);
- this._iVal = (short)i;
- super._null = false;
- }
-
- public void setString(String x) throws SQLException {
- Integer i = new Integer(x);
- int s = i;
- this.validateRange(s);
- this._iVal = (short)s;
- super._null = false;
- }
-
- public int getSQLType() {
- return 5;
- }
-
- public Object getObject() throws SQLException {
- return new Integer(this._iVal);
- }
-
- public void setObject(Object obj) throws SQLException {
- this.setInt((Integer)obj);
- }
-
- void validateRange(int x) throws SQLException {
- if (x < -32768 || x > 32767) {
- throw new SQLException("Data out of range for SmallInt");
- }
- }
-
- void validateRange(long x) throws SQLException {
- if (x < -32768L || x > 32767L) {
- throw new SQLException("Data out of range for SmallInt");
- }
- }
- }
-